-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update/i18n utils unreverted #47492
Update/i18n utils unreverted #47492
Conversation
return { | ||
__: i18n.__.bind( i18n ), | ||
_n: i18n._n.bind( i18n ), | ||
_nx: i18n._nx.bind( i18n ), | ||
_x: i18n._x.bind( i18n ), | ||
isRTL: i18n.isRTL.bind( i18n ), | ||
i18nLocale, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably need to roll this change back and keep it around for a bit - breaking change. (and widely used in calypso) ... What's -alpha mean in the version number? Is that basically like saying this isn't semver?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's -alpha mean in the version number? Is that basically like saying this isn't semver?
That's how pre-release versions are denoted according to SemVer's specs. Ref: https://semver.org/#spec-item-9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So safe to break backward compat here then, thanks for the link 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also not sure that @automattic/react-i18n
is used anywhere outside of a8c either so I was just planning to udpate all the uses. It looks like there is a package on the npm registry but it's private.
Here is how your PR affects size of JS and CSS bundles shipped to the user's browser: App Entrypoints (~593 bytes added 📈 [gzipped])
Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used. Async-loaded Components (~52 bytes added 📈 [gzipped])
React components that are loaded lazily, when a certain part of UI is displayed for the first time. Legend What is parsed and gzip size?Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory. Generated by performance advisor bot at iscalypsofastyet.com. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good. I still need to make some changes to my PR since it currently breaks the build I believe, which means that some of these changes will probably disappear after a rebase.
return { | ||
__: i18n.__.bind( i18n ), | ||
_n: i18n._n.bind( i18n ), | ||
_nx: i18n._nx.bind( i18n ), | ||
_x: i18n._x.bind( i18n ), | ||
isRTL: i18n.isRTL.bind( i18n ), | ||
i18nLocale, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also not sure that @automattic/react-i18n
is used anywhere outside of a8c either so I was just planning to udpate all the uses. It looks like there is a package on the npm registry but it's private.
@@ -132,3 +128,14 @@ export function localizeUrl( fullUrl: string, toLocale?: Locale ): string { | |||
// Nothing needed to be changed, just return it unmodified. | |||
return fullUrl; | |||
} | |||
|
|||
export function useLocalizeUrl(): ( fullUrl: string, locale?: Locale ) => string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Co-authored-by: Philip Jackson <p-jackson@live.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a few small remarks, but overall it LGTM 🚀
@@ -25,7 +27,11 @@ const CalypsoI18nProvider: React.FunctionComponent = ( { children } ) => { | |||
}; | |||
}, [] ); | |||
|
|||
return <I18nProvider localeData={ localeData }>{ children }</I18nProvider>; | |||
return ( | |||
<LocaleProvider localeSlug={ localeSlug || 'en' }> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use config( 'i18n_default_locale_slug' )
for fallback instead of 'en'
string literal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, TIL! There's some other places I can use this config value too 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exposed and used the hard coded one in i18n-utils, I think we need to strip these i18n config values from calypso usage and rely on the utils package unless we want to configure LocaleProvider with the configuration as well?
This is done in #47613
Context: #47352 (comment)
Follows up on @p-jackson's #47446 to introduce
useLocale
, incorporates some changes from #47358 to decouple i18n-utils fromgetLocaleSlug
(i18n-calypso package), but instead of replacing getLocaleSlug withreact-i18n
'suseI18n
, it uses its ownuseLocale
.i18n-utils is now completely free of all deps but does expect the LocaleProvider to be configured.
warning: Pretty sure I haven't got this set up right yet. Manual testing was showing localizeUrl wasn't working in the
/new/domains/es
gutenboarding context.Please suggest anything you see that can be dropped from this PR without causing any knock on effects - e.g. we can probably drop changes to domain-picker.
Changes proposed in this Pull Request
Testing instructions
Fixes #